<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2016/11/8
 * Time: 11:12
 * Project name: PHPTEST
 * File name: 1.php
 * @copyright Copyright (c) 2016 ZRX Software LLC
 * @license https://github.com/zhangrxiang
 * @since 1.0.0
 */


br("比较两个数组的键名和键值，并返回差集：array_diff_assoc(array1,array2,array3...);");
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
$a2 = array("a" => "red", "b" => "green1", "c" => "blue");
br($a1);
br($a2);
$result = array_diff_assoc($a1, $a2);
br($result);

br();


br("array_diff() 函数用于比较两个（或更多个）数组的键值，并返回差集。array_diff");
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
$a2 = array("e" => "red", "f" => "green", "g" => "blue");
br($a1);
br($a2);
$result = array_diff($a1, $a2);
br($result);
br();


br("array_count_values() 函数用于统计数组中所有值出现的次数:array_count_values(array)");
$a = array("A", "Cat", "Dog", "A", "Dog");
br($a);
br(array_count_values($a));
br();


br("通过合并两个数组来创建一个新数组，一个元素为键名，另一个元素为键值：array_combine(keys,values);");
$fname = array("Peter", "Ben", "Joe");
$age = array("35", "37", "43");
$c = array_combine($fname, $age);
br($fname);
br($age);
br($c);
br();

br("把数组分割为带有两个元素的数组块：array_chunk(array,size,preserve_keys); ");
$cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes", "Opel");
br($cars);
br(array_chunk($cars, 2));


br();//将数组的所有的键转换为大写或小写字母：
br("将数组的所有的键转换为大写或小写字母:array_change_key_case");
$age = array("Peter" => "35", "Ben" => "37", "Joe" => "43");
br(array_change_key_case($age, CASE_UPPER));
br();
br(array_change_key_case($age, CASE_LOWER));

function br($result = null)
{
    if (is_array($result)) {
        echo "<pre>";
        var_dump($result);
        echo "</pre>";
    }
    if (is_string($result)) {
        echo "<br>------------------------------$result----------------------------------<br>";
    }
    if (is_null($result)) {
        echo "<br>";
    }
}